package com.majun.huaxishe.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.majun.huaxishe.entity.Photos;
import com.majun.huaxishe.entity.dto.PhotosDTO;
import com.majun.huaxishe.entity.vo.PhotosVO;
import com.majun.huaxishe.mapper.PhotosMapper;
import com.majun.huaxishe.service.IPhotosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 照片表 服务实现类
 * </p>
 *
 * @author 马骏
 * @since 2024-02-29
 */
@Service
public class PhotosServiceImpl extends ServiceImpl<PhotosMapper, Photos> implements IPhotosService {

    @Autowired
    private PhotosMapper photosMapper;

    @Override
    public Map<Integer, Integer> countByAlbumId(List<Integer> albumIds) {
        List<PhotosVO> photosVOS = photosMapper.countByAlbumId(albumIds);
        return photosVOS.stream().collect(Collectors.toMap(PhotosVO::getAlbumId, PhotosVO::getCount));
    }

    @Override
    public Page<PhotosVO> queryPage(PhotosDTO photosDTO) {
        String name = photosDTO.getName();
        Integer albumId = photosDTO.getAlbumId();
        return photosMapper.queryPage(new Page<PhotosVO>(photosDTO.getCurrentPage(),
                        photosDTO.getPageSize()), name, albumId);
    }
}
